package sctu.edu.java.year2016.team04.luoxinghua.day20160605.chapter12_2;

import java.io.*;
import java.util.Scanner;

/**
 * Created by 落叶的思恋 on 2016/6/13.
 * 用字符输入输出流输入字符将一段文字加密后存入文件，然后读取，并将加密前加密后的文件输出
 */
public class EncryptWork12_2 {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        File file = new File("D:\\Work", "work12-2.txt");
        if (file.exists()) {
            System.out.println("file already exists");
            file.delete();
        } else
            file.createNewFile();
        String str = scan.nextLine();
        String temp = str;
        int strnum[] = new int[str.length()];
        for (int i = 0; i < str.length(); i++) {
            strnum[i] = str.charAt(i) - 3;
        }
        str=strnum.toString();
        byte[] bytes = new byte[2048];
        bytes = str.getBytes();
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(bytes);
        FileInputStream fileInputStream = new FileInputStream(file);
        InputStreamReader inputStream = new InputStreamReader(fileInputStream);
        int numbytes = fileInputStream.available();
        byte[] readfile = new byte[numbytes];
        BufferedReader br = new BufferedReader(inputStream);
        String line = null;
        System.out.println("encrypted is");
        while ((line = br.readLine()) != null) {
            System.out.println(line);

        }
        System.out.println("no encrypted :" + temp);

    }

}
